package by.exposit.controller;

import by.exposit.service.ProjectService;
import by.exposit.service.RequestService;
import by.exposit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * Created by HaRiA on 24.07.2014.
 */
@Controller
@RequestMapping("users")
public  class UserController
{
    @Autowired
    private UserService userService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private RequestService requestService;

   private Date date = new Date();

     @RequestMapping(value = {"/menu"},method = RequestMethod.GET)
    public ModelAndView home(HttpSession session, Model model)
    {
        session.getAttribute("user");
        ModelAndView mav= new ModelAndView();
        session.setAttribute("prevpage","users/menu");
        mav.setViewName("users/menu");
        return mav;
    }

   @RequestMapping(value = "profile/{userId}",method = RequestMethod.GET)
    public  ModelAndView profile(
           @PathVariable String userId,
           HttpSession session)
   {

      ModelAndView mav = new ModelAndView();

      mav.addObject((String) session.getAttribute("prevpage"));

       mav.addObject("userId",userId);
       mav.setViewName("users/profile");
      return  mav;
   }
}
